﻿using Core.Framework.Model.Common;
using Core.Framework.Model.WebSockets;
using Core.Framework.Util;
using Core.IBusiness.IPushModule.Model;
using Core.IBusiness.ISocketModule;
using System;
using System.Collections.Generic;
using System.Text;

namespace Core.Business.PushModule
{
    internal class Utils
    {

        IQueue iQueue;

        public Utils(IQueue queue)
        {
            this.iQueue = queue;
        }

        /// <summary>
        /// 发布帮助类库
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="model"></param>
        /// <returns></returns>
        public MethodResult<bool> PublishHelper<T>(BasePush<T> model) where T : class
        {
            var message = this.GetQueryMessage(model);
            var result = this.iQueue.Publish(message);
            return result;
        }

        private QueryMessage GetQueryMessage<T>(BasePush<T> model) where T : class
        {
            var message = new QueryMessage
            {
                MessageKey = model.MessageKey,
                Template = model.Template,
                Content = model.Title,
                MessageType = model.MessageType,
                Parameter = model.MessageContent.TryToJson(),
                ClientToken = model.ClientToken,
                IsMustBeServed = model.IsMustBeServed
            };

            return message;
        }
    }
}
